package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.situ.mall.mapper.CategoryMapper;
import com.situ.mall.pojo.entity.Category;
import com.situ.mall.pojo.entity.Product;
import com.situ.mall.pojo.vo.CategoryCountVO;
import com.situ.mall.service.ICategoryService;
import com.situ.mall.util.JSONResult;

@Service
public class CategoryServiceImpl implements ICategoryService{
	@Autowired
	CategoryMapper categorpMapper;
	
	@Override
	public JSONResult selectBypage(Integer page, Integer limit, String name) {
		int offset = (page - 1) * limit;
		List<Category> list = categorpMapper.selectByPage(offset, limit, name);
		int count = categorpMapper.selectTotalCount(name);
		return JSONResult.success(list, count);
	}

	@Override
	public boolean deleteByPrimaryKey(Integer id) {
		int count = categorpMapper.deleteByPrimaryKey(id);
		return count == 1;
	}

	@Override
	public boolean deleteAll(Integer[] ids) {
		int count = categorpMapper.deleteAllByArray(ids);
		return count == ids.length;
	}

	@Override
	public List<Category> selectTopCategory() {
		List<Category> list = categorpMapper.selectTopCategory();
		return list;
	}

	@Override
	public List<Category> selectSecondCategory(Integer id) {
		List<Category> list = categorpMapper.selectSecondCategory(id);
		return list;
	}

	@Override
	public JSONResult selectCategoryCount() {
		List<CategoryCountVO> list = categorpMapper.selectCategoryCount();
		return JSONResult.success(list);
	}

	@Override
	public List<Category> selectSecondCategoryList() {
		List<Category> list = categorpMapper.selectSecondCategoryToFront();
		return list;
	}

	@Override
	public Integer selectParentIdByProduct(Integer categoryId) {
		Integer parentId = categorpMapper.selectParentIdByProduct(categoryId);
		return parentId;
	}

}
